require('./index.scss');
var Tool = require('common/tool');
require('comp/table');
require('comp/dialog');
var page ;

var vm = avalon.define({
    $id: 'backlog',
    lang: _language=='zh' ? 'CN':'TW',
    step:1,                                     // 1 第一步 填写存款信息  2 第二步 确认存款信息
    /* 存款申请集合 */
    depositList:{
        thList:[
            {label:'申请编号',text:"pno"},
            {label:'平台',text:"platform"},
            {label:'账号',text:"accountNo"},
            {label:'存款金额',text:"transAmount"},
            {label:'币种',text:"transCurrency"},
            {label:'申请时间',text:function(v){
                return Tool.timeZone(v.createDate);
            }},
            {label:'进度',text:function(){
                return '<span class="primary">处理中</span>';
            }},
        ],
        list:''
    },
    /* 账户级别变更申请 */
    upOrDownList:{
        thList:[
            {label:'申请编号',text:"pno"},
            {label:'申请类型',text:"proposalType"},
            {label:'平台',text:"platform"},
            {label:'账号',text:"accountNo"},
            {label:'原账户级别',text:"fromAccountGroupLevel"},
            {label:'更改后账户级别',text:"toAccountGroupLevel"},
            {label:'申请时间',text:function(v){
                return Tool.timeZone(v.createDate);
            }},
            {label:'进度',text:function(){
                return '<span class="primary">处理中</span>';
            }},
        ],
        list:''
    },
    /* 取款申请 */
    extract:{
        thList:[
            {label:'申请编号',text:function(v){
                return '<a href="javascript:;" class="pno" data-pno="'+v.pno+'">'+v.pno+'</a>';
            }},
            {label:'平台',text:"platform"},
            {label:'账号',text:"accountNo"},
            {label:'取款金额',text:"transAmount"},
            {label:'账户币种',text:"accountCurrency"},
            {label:'取款时间',text:function(v){
                return Tool.timeZone(v.createDate);
            }},
            {label:'进度',text:function(){
                return '<span class="primary">处理中</span>';
            }},
            {label:'更新时间',text:function(v){
                return Tool.timeZone(v.withdrawalSettleTime);
            }},
        ],
        list:''
    },
    /* 转账申请集合 */
    cashTransferList:{
        thList:[
            {label:'申请编号',text:"pno"},
            {label:'平台',text:"platform"},
            {label:'账号',text:"accountNo"},
            {label:'取款金额',text:"transAmount"},
            {label:'账户币种',text:"accountCurrency"},
            {label:'取款时间',text:function(v){
                return Tool.timeZone(v.createDate);
            }},
            {label:'进度',text:function(){
                return '<span class="primary">处理中</span>';
            }},
            {label:'更新时间',text:function(v){
                return Tool.timeZone(v.withdrawalSettleTime);
            }},
        ],
        list:''
    },
    // 取款弹窗的信息
    extractInfo:{
        loading:false,
    },
    sumFproposalNum : '',
    /* 取款详情的弹窗 */
    extractDialog:{
        loading:false,
        display:'none',
        title: '取款详情',
        statusArr:{
            '0':'申请已提交',
            '1':'审批中',
            '2':'审批通过',
            '3':'支付成功',
            '4':'支付失败',
            '-1':'申请已取消',
            '-2':'申请已取消',
            '-3':'申请已取消',
            '-4':'取款失败',
        },
        className: 'extractDialog',
        withdrawProposal:'',
        WithdrawalogList:'',
    },
});

vm.$watch('onReady',function(){
    page = new Backlog();
    window['vm'] = vm;

    $("#extractList").on('click','.pno',function(){
        var _pno = $(this).attr('data-pno');
        page.extractDetail(_pno);
    });

});

function Backlog(){
    this.queryList();
}

// 获取存款页面信息
Backlog.prototype.queryList = function(){
    Tool.ajax({
        url:'/unfinishProceeding',
        type:'post'
    }).done(function(res){

        var data = res.data;
        vm.depositList.list = data.depositList;
        vm.cashTransferList.list = data.cashTransferList;
        vm.extract.list = data.withdrawalProposalList;
        vm.upOrDownList.list = data.upOrDownList;
        vm.sumFproposalNum = data.sumFproposalNum;

    });
}

// 取款提案详情
Backlog.prototype.extractDetail = function(_id){
    var that = this;
    if(vm.extractDialog.loading === true) return;
    vm.extractDialog.loading = true;
    vm.extractDialog.display = 'block';
    vm.extractDialog.title = _id+'取款详情';
    Tool.ajax({
        url: '/fundDrawingDetail',
        data:{
            proposalNo:_id
        },
        type:"post"
    }).done(function(res){
        vm.extractDialog.loading = false;

        var data = res.data,
            withdrawProposal = data.withdrawProposal;
        if( !withdrawProposal.payCurrency ) withdrawProposal.payCurrency = '';
        vm.extractDialog.withdrawProposal = withdrawProposal;
        data.WithdrawalogList.forEach(function(v,i){
            v.settleTimeStr = Tool.timeZone(v.settleTime);
        });
        vm.extractDialog.WithdrawalogList = data.WithdrawalogList;
    });
}